<?php
namespace app\service;

use app\service\ChessHelper;
use app\service\PachCreate;

class ChessPlay
{
	// 棋谱FEN串
	private $_fenString = '';
	// 棋谱一维数组
	private $_board = [];
	// 棋子数组
	private $_pieces = [];
	// 走棋方
	private $_side = 0;
	
	public function __construct($fenString)
	{
		$this->_fenString = $fenString;
		$this->_board = array_fill(0, 256, 0);
		$this->_pieces = array_fill(0, 48, 0);
		ChessHelper::stringToArray($fenString, $this->_side, $this->_board, $this->_pieces);
	}
	
	public function play()
	{
		$pachCreate = new PachCreate();
		$pachCreate->setBoard($this->_board);
		$pachCreate->setSide($this->_side);
		$pachCreate->setPieces($this->_pieces);
		//$pachCreate->minMaxSearch();
		//$pachCreate->negaMaxSearch();
		$pachCreate->alphaBetaSearch(3, -30000, 30000);
		$path = $pachCreate->getBestMove();
		$path[] = $pachCreate->times;
		//$pachCreate->knightMove(array_search(37, $this->_board));
		//$pachCreate->kingMove(array_search(32, $this->_board));
		//$pachCreate->advisorMove(array_search(33, $this->_board));
		//$pachCreate->bishopMove(array_search(35, $this->_board));
		//$pachCreate->rookMove(array_search(39, $this->_board));
		//$pachCreate->cannonMove(array_search(41, $this->_board));
		//$pachCreate->pawnMove(array_search(43, $this->_board));
// 		$moveList = [];
// 		$pachCreate->genAllMove($moveList);
		//$moveList = $pachCreate->getMoveList();
		return $path;
	}
}